package com.hwl.demo3.component;

import com.hwl.demo3.service.impl.CashSuper;

/**
 * @author sentry
 * @since 2023-02-28
 */
public class CashReturn extends CashSuper {

    private final double moneyCondition;
    private final double moneyReturn;

    /**
     * 返利收费，初始化时必须输入返利条件和返利值
     */
    public CashReturn(double moneyCondition, double moneyReturn) {
        this.moneyCondition = moneyCondition;
        this.moneyReturn = moneyReturn;
    }

    @Override
    public double acceptCash(double price, int num) {
        double result = price * num;
        if (moneyCondition > 0 && moneyReturn > 0 && result >= moneyCondition) {
            result = result - Math.floor(result / moneyCondition) * moneyReturn;
        }
        return super.acceptCash(result, 1);
    }
}
